﻿<!DOCTYPE html>
<html lang="en-us">

<head>
    <title>送检单报告
    </title>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <link rel="icon" href="favicon.ico" />
    <link href="css/bootstrap.min.css" rel="stylesheet" />
    <link href="css/font-awesome.min.css" rel="stylesheet" />
    <link href="css/default.css" rel="stylesheet" type="text/css" />
    <script src="js/jquery.min.js"></script>
    <script src="js/bootstrap/bootstrap.min.js"></script>
    <script src="js/bootstrap/bootstrap-table.min.js"></script>
    <script src="js/bootstrap/bootstrap-table-zh-CN.min.js"></script>
    <!--[if lt IE 9]>
      <script src="js/bootstrap/html5shiv.min.js"></script>
      <script src="js/bootstrap/respond.min.js"></script>
    <![endif]-->
    <!--页面加载进度条-->
    <link href="css/pace/dataurl.css" rel="stylesheet" />
    <script src="js/pace/pace.min.js"></script>
    <script src="js/jquery.scrolltopcontrol/scrolltopcontrol.js" type="text/javascript"></script>
    <script src="js/jquery.extend.js" type="text/javascript"></script>
    <script src="js/default.js" type="text/javascript"></script>
    <script src="js/jqueryrotate.js" type="text/javascript"></script>
    <script src="js/fileServer.js"></script>
    <!-- 下拉菜单 -->
    <link href="./css/bootstrap-select/bootstrap-select.min.css" rel="stylesheet" />
    <script src="./js/bootstrap-select/bootstrap-select.min.js"></script>
    <script src="./js/bootstrap-select/i18n/defaults-zh_CN.min.js"></script>
    <script src="./js/bootstrap-select/bootstrap-select-custom.js"></script>
    <!-- artTemplate 模板引擎 -->
    <script src="js/template-web.js" type="text/javascript"></script>
    <!-- excel导出操作-->
    <script src="js/exportTable.js"></script>
    <style>
        html,
        body {
            width: 100%;
            height: 100%;
        }

        .fixed-table-header {
            display: none !important;
        }

        #id-card-photo-wrapper {
            display: none;
            width: 720px;
            height: 480px;
            position: fixed;
            left: 50%;
            top: 50%;
            transform: translate(-50%, -50%);
        }

        #id-card-photo-wrapper #ic-rotate {
            position: absolute;
            right: 0;
            top: 0;
            width: 33px;
            height: 33px;
            line-height: 33px;
            text-align: center;
            background: #fff;
            cursor: pointer;
            box-shadow: 2px 2px 2px #eee, -2px -2px 2px #eee;
        }

        #id-card-photo-wrapper .arrow {
            transform: translateY(-50%);
            width: 40px;
            height: 72px;
            font-size: 32px;
            line-height: 72px;
            text-align: center;
            color: #fff;
            font-weight: 300;
            background: rgba(0, 0, 0, .2);
            cursor: pointer;
            position: absolute;
            right: 10px;
            top: 50%;
            font-family: -webkit-body;
        }

        #id-card-photo-wrapper .arrow:hover {
            background: rgba(0, 0, 0, .3);
        }

        #id-card-photo-wrapper .arrow.l {
            left: 10px;
        }

        #id-card-photo {
            background: #fff;
            padding: 10px;
            display: block;
            width: 100%;
            height: 100%;
            box-shadow: 2px 2px 5px #ddd, -2px -2px 5px #ddd;
        }

        .bootstrap-table {
            padding: 10px 16px;
        }

        .agree-item {
            color: #a94442;
        }

        .params-warpper {
            display: flex;
            flex-direction: row;
            padding-right: 200px;
        }

        #search-btn {
            position: absolute;
            right: 50px;
            top: 50%;
            transform: translateY(-50%);
            width: 100px;
        }

        .params-warpper .params-item {
            flex: 1;
            display: flex;
            flex-direction: row;
            margin-top: 10px;
        }

        .params-warpper .params-item label {
            display: inline-block;
            min-width: 120px;
            line-height: 34px;
            text-align: right;
            letter-spacing: 2px;
        }

        .params-warpper .params-item .value {
            flex: 1;
        }

        .maincontent {
            min-width: 1000px !important;
            overflow: auto !important;
            overflow-x: scroll !important;
        }

        .link {
            color: #f7a591;
            outline: none;
        }

        .link:hover {
            color: #f7a591;
        }

        .pagination>li>a,
        .pagination>li>span {
            color: #f7a591;
        }

        .pagination>.active>a,
        .pagination>.active>a:focus,
        .pagination>.active>a:hover,
        .pagination>.active>span,
        .pagination>.active>span:focus,
        .pagination>.active>span:hover {
            border-color: #f7a591;
            background-color: #f7a591;
        }
        .zhezhao{
            position: fixed;
            left: 0;
            top: 0;
            right: 0;
            bottom: 0;
            background: #000;
            opacity: 0.5;
            display: none;
            z-index: 1;
        }
        .sample-alert{
            position: fixed;
            left: 50%;
            top: 50%;
            transform: translate(-50%,-50%);
            width: 400px;
            height: 300px;
            text-align: center;
            /*line-height: 40px;*/
            /*text-align: center;*/
            background: #fff;
            border-radius: 5px;
            font-size: 16px;
            display: none;
            z-index: 2;
        }
        .sample-alert .div-top{
            margin-top: 40px;
        }
        .sample-alert .div-top #sampleNum{
            width: 200px;
            height: 30px;
            border: 1px solid #dfdfdf;
            border-radius: 5px;
        }
        .sample-alert .div-bottom{
            margin-top: 50px;
        }
        .sample-alert .div-bottom .sample-commit,.cancel{
            display: inline-block;
            width: 60px;
            height: 40px;
            line-height: 40px;
            color: #fff;
            background: #f7a591;
            border-radius: 5px;
            cursor: pointer;
        }
        .sample-alert .div-bottom .sample-commit{
            margin-right: 20px;
        }
        .sample-alert .params-item .control-label,select{
            display: inline-block;
        }
        .sample-alert .params-item select{
            width: 200px;
            height: 30px;
            border: 1px solid #dfdfdf;
            border-radius: 5px;
        }
    </style>


</head>

<body>

        <div class="maincontent">
            <!--我是主要内容-->
            <div class="panel panel-default">
                <div class="panel-heading">
                    查询条件
                </div>
                <div class="panel-body form-group" style="margin-bottom:0px; position:relative;">
                    <div class="params-warpper">
                        <div class="params-item">
                            <label class="control-label">受检者姓名：</label>
                            <input type="text" placeholder="请输入受检者姓名" class="form-control value" id="sampleName" />
                        </div>
                        <div class="params-item">
                            <label class="control-label">送检单号：</label>
                            <input type="text" placeholder="请输入送检单号" class="form-control value" id="sampleId" />
                        </div>
                        <div class="params-item">
                            <label class="control-label">状态：</label>
                            <select type="text" class="form-control value" id="status">
                                <option value=''>请选择状态</option>
                                <option value="0">未推送</option>
                                <option value="1">已推送</option>
                                <option value="2">推送失败</option>
                                <option value="3">已出报告</option>
                                <option value="4">送检单失效</option>
                            </select>
                        </div>
                    </div>
                    <div class="params-warpper">
                        <div class="params-item">
                            <label class="control-label">送检医院：</label>
                            <select id="search-customer" class="selectpicker form-control value" data-live-search="true" data-max-options="1">
                            </select>
                        </div>
                        <div class="params-item">
                            <label class="control-label">检测类型：</label>
                            <select name="productName" id="productName" class="form-control value">
                                <option value="">请选择</option>
                                <option value="耳聋基因检测">耳聋基因检测</option>
                                <option value="NIPT检测">NIPT检测</option>
                                <option value="HPV检测">HPV检测</option>
                                <option value="产前血清学筛查">产前血清学筛查</option>
                                <option value="新生儿疾病筛查">新生儿疾病筛查</option>
                                <option value="地中海贫血基因检测">地中海贫血基因检测</option>
                            </select>
                        </div>
                        <div class="params-item">
                            <label class="control-label">免费券编码：</label>
                            <input type="text" placeholder="请输入免费券编码" class="form-control value" id="couponCode" />
                        </div>
                    </div>
                    <div class="params-warpper">
                        <div class="params-item">
                            <label class="control-label">受检者身份证：</label>
                            <input type="text" placeholder="请输入受检者身份证" class="form-control value" id="idCard" />
                        </div>
                        <div class="params-item">
                            <label class="control-label">扫码采样日期：</label>
                            <input type="text" placeholder="开始日期" class="form-control value" id="search-scan-start-time" onblur="(this.type='text')"
                                   onfocus="(this.type='date')" />
                            <span class="split">~</span>
                            <input type="text" placeholder="结束日期" class="form-control value" id="search-scan-end-time" onblur="(this.type='text')" onfocus="(this.type='date')"
                            />
                        </div>
                        <div class="params-item">
                            <label class="control-label">检测结果：</label>
                            <select type="text" class="form-control value" id="result">
                                <option value=''>请选择状态</option>
                                <option value="1">高风险</option>
                                <option value="2">低风险</option>
                                <option value="3">正常</option>
                                <option value="4">异常</option>
                            </select>
                        </div>
                    </div>
                    <div class="params-warpper">
                        <div class="params-item">
                            <label class="control-label">样本编号：</label>
                            <input type="text" placeholder="请输入样本编号" class="form-control value" id="inputSampleNum" onclick="inputSampleNumDele()" onkeydown="whetherSearchBtnClick()"/>
                        </div>
                        <div class="params-item"></div>
                        <div class="params-item"></div>
                    </div>


                    <button class="btn btn-primary" id="search-btn" onclick="searchBtnClick()">查询</button>
                </div>
            </div>
            <input type="hidden" id="pageSize">
            <input type="hidden" id="pageNum">
            <table id="mytab" class="table table-hover"  ></table>
            <div id="toolbar" class="btn-group pull-right" style="margin-right: 20px;" >
                <button id="btn_send" type="button" class="btn btn-primary">
                    <span class=" " aria-hidden="true"></span>推送
                </button>
                <button id="btn_get" type="button" class="btn btn-primary" style="margin-left: 30px">
                    <span class=" " aria-hidden="true"></span>获取
                </button>
                <a style="margin-left: 30px" href="javascript:void(0)" onclick="callParent('上传结果','sample_report_upload.html')" class="btn btn-primary add-sample">导入报告结果</a>
            </div>
        </div>
        <div class="zhezhao"></div>
        <div class="sample-alert">
            <div class="div-top params-warpper">
                <div class="params-item">
                    <label>　样品编号：</label><input type="text" id="sampleNum" placeholder="请输入样品编号">
                </div>
            </div>
            <div class="params-warpper">
                <div class="params-item">
                    <label class="control-label">　样品类型：</label>
                    <select name="sampleType" style="width: 200px" id="sampleType" class="selectpicker form-control value" data-live-search="true" data-max-options="1"></select>
                </div>
            </div>
            <div class="params-warpper">
                <div class="params-item">
                    <label class="control-label">采血管类型：</label>
                    <select name="tubeType" id="tubeType" class="form-control value">
                        <option value="">请选择</option>
                        <option value="0">STRECK</option>
                        <option value="1">EDTA</option>
                        <option value="2">K牌采血管</option>
                        <option value="5">G牌采血管</option>
                        <option value="3">T管</option>
                        <option value="4">K牌采血管-新型试生产(测试专用)</option>
                    </select>
                </div>
            </div>
            <input type="hidden" id="sampleBaseId"  >
            <div class="div-bottom">
                <span class="sample-commit" onclick="addSampleBaseNum()">保存</span>
                <span class="cancel" onclick="closeAlert()">取消</span>
            </div>
        </div>
    <a href="#top" id="goTop">
        <i class="fa fa-angle-up fa-3x"></i>
    </a>


    <script>
        var isLoadingAllData = true;//标识当前是不是在加载全部数据
		var isClickExportBtn = false;//标识当前是不是点击了导出按钮
		//请求全部数据
		$.ajax({
			method: 'POST',
			url: '/csfy/ws/getSampleBaseList.do',
			success: function (res) {
				isLoadingAllData = false;
				if (res && res.code && res.code == 200) {
					dataList = res.rows;
					if(isClickExportBtn) {
						flag = true;
						isClickExportBtn = false;
						$("#fountainTextG").show();
						setTimeout(() => {
							exportCouponExcel(dataList)
						}, 0);
						handleLoading()
					}
				} 
			},
			error: function (err) {
				isLoadingAllData = false
			}
        });

        //  请求获取所有样品种类
        $.ajax({
            method: 'POST',
            url: '/csfy/ws/getSampleTypeList.do',
            success: function (res) {
                var getData = JSON.parse(res);
                if(getData.code == 200){
                    var sampleTypeList = getData.rows || [];
                    var sampleTypeOptions = '<option value="">请选择</option>';
                    sampleTypeList.forEach(sample => {
                        sampleTypeOptions += '<option value="' + sample.code + '">' + sample.name + '</option>';
                });
                    $('#sampleType').html(sampleTypeOptions);
                    $('.selectpicker').selectpicker('refresh');
                }


            },
            error: function (err) {
                alert("网络异常");
            }
        });

        
        //总条目
        var total = 0;
        //总数据列表
        var dataList = null;
        var exportTimer = null;
        function handleLoading() {
            exportTimer && window.clearInterval(exportTimer);
            exportTimer = null;
            exportTimer = setInterval(() => {
                if (window.sessionStorage.getItem('exportFinished')) {
                    flag = false;
                    $("#fountainTextG").hide();
                    window.sessionStorage.removeItem('exportFinished');
                    exportTimer && window.clearInterval(exportTimer);
                    exportTimer = null;
					isClickExportBtn = false
                }
            }, 1000)
        }

        //医院列表
        $.ajax({
            method: 'POST',
            url: '/csfy/intf.do',
            data: {
                method: 'getCustomers',
                addressCity: '长沙市',
            },
            success: function (res) {
                if (res && res.code == 200) {
                    var customerList = res.rows || [];
                    var customerOptions = '<option value="">请选择医院</option>';
                    customerList.forEach(customer => {
                        customerOptions += '<option value="' + customer.customerCode + '">' + customer.customerName + '</option>';
                    });
                    $('#search-customer').html(customerOptions);
                    $('.selectpicker').selectpicker('refresh');
                }
            }
        });



        //退出登录
        function logout() {
            $.ajax({
                url: '/csfy/dologout.do',
                method: 'POST',
                success: function (res) {
                    if (JSON.parse(res).code == 200) {
                        window.location.href = "/csfy/index.do"
                    }
                }
            })
        }






        Date.prototype.pattern = function (fmt) {
            var o = {
                "M+": this.getMonth() + 1, //月份
                "d+": this.getDate(), //日
                "h+": this.getHours() % 12 == 0 ? 12 : this.getHours() % 12, //小时
                "H+": this.getHours(), //小时
                "m+": this.getMinutes(), //分
                "s+": this.getSeconds(), //秒
                "q+": Math.floor((this.getMonth() + 3) / 3), //季度
                "S": this.getMilliseconds() //毫秒
            };
            var week = {
                "0": "/u65e5",
                "1": "/u4e00",
                "2": "/u4e8c",
                "3": "/u4e09",
                "4": "/u56db",
                "5": "/u4e94",
                "6": "/u516d"
            };
            if (/(y+)/.test(fmt)) {
                fmt = fmt.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length));
            }
            if (/(E+)/.test(fmt)) {
                fmt = fmt.replace(RegExp.$1, ((RegExp.$1.length > 1) ? (RegExp.$1.length > 2 ? "/u661f/u671f" : "/u5468") : '') + week[this.getDay() + '']);
            }
            for (var k in o) {
                if (new RegExp("(" + k + ")").test(fmt)) {
                    fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(('' + o[k]).length)));
                }
            }
            return fmt;
        };
        //根据窗口调整表格高度
        $(window).resize(function () {
            $('#mytab').bootstrapTable('resetView', {
                height: 10000
            })
        });
        //生成用户数据
        $('#mytab').bootstrapTable({
            method: 'POST',
            contentType: "application/x-www-form-urlencoded",//必须要有！！！！
            url: "/csfy/ws/getSampleBaseList.do",//要请求数据的文件路径
            height: tableHeight(),//高度调整
            toolbar: '#toolbar',//指定工具栏
            striped: true, //是否显示行间隔色
            dataField: "rows",//bootstrap table 可以前端分页也可以后端分页，这里
            //我们使用的是后端分页，后端分页时需返回含有total：总记录数,这个键值好像是固定的
            //rows： 记录集合 键值可以修改  dataField 自己定义成自己想要的就好
            pageNumber: 1, //初始化加载第一页，默认第一页
            pagination: true,//是否分页
            queryParamsType: 'limit',//查询参数组织方式
            queryParams: queryParams,//请求服务器时所传的参数
            sidePagination: 'server',//指定服务器端分页
            pageSize: 10,//单页记录数
            pageList: [5, 10, 20, 30],//分页步进值
            showRefresh: true,//刷新按钮
            // showColumns: true,
            clickToSelect: true,//是否启用点击选中行
            toolbarAlign: 'left', //工具栏对齐方式
            buttonsAlign: 'left',//按钮对齐方式
            toolbar: '#toolbar',//指定工作栏
            columns: [
                                {
                                    title: '全选',
                                    field: 'select',
                                    //复选框
                                    checkbox: true,
                                    width: 20,
                                    align: 'center',
                                    valign: 'middle'
                                },
                {
                    title: '送检单号',
                    field: 'sampleBaseId',
                },
                {
                    title: '受检者姓名',
                    field: 'sampleName',
                },
                {
                    title: '优惠卷编码',
                    field: 'couponCode',
                },
                {
                    title: '检测类型',
                    field: 'productName',
                },
                {
                    title: '采样时间',
                    field: 'scannerTime',
                    formatter: formatScannerTime

                },
                {
                    title: '推送时间',
                    align: 'center',
                    formatter: formatSendDateTime
                },
                {
                    title: '样品编号',
                    field: 'sampleNum',
                },
                {
                    title: '送检医院',
                    field: 'sendHospitalName'
                },
                {
                    title: '报告接收时间',
                    formatter: formatGetTime
                },
                {
                    title: '发送次数',
                    field:'count'
                },

                {
                    title: '状态',

                    formatter: formatStatus
                },

                {
                    title: '检测结果',
                    field: 'sampleResult',
                },
                {
                    title: '操作',
                    align: 'center',
                    //列数据格式化
                    formatter: operateFormatter
                }
            ],
            locale: 'zh-CN',//中文支持,
            responseHandler: function (res) {
                //在ajax获取到数据，渲染表格之前，修改数据源
                total = res.total || 0;
                return res;
            },
            onRefresh: function (params) {
                if (params && params.query) {
                    return false;
                }
                $("#sampleName").val('');
                $("#sampleId").val('');
                $("#status").val('');
                $("#sendHospitalName").val('');
                $("#productName").val('');
                $("#couponCode").val('');
                $("#search-scan-start-time").val('');
                $("#search-scan-end-time").val('');
                $("#result").val('');
            }
        });
        function toDetail(id) {
            window.location.href = "/csfy/static/manage-sys/coupon-detail.html?id=" + id
        }

        function formatScannerTime(value, row, index){
            if(value != null){
                return value.substring(0,value.length - 2);
            }else{
                return "";
            }
        }

        function formatSendDateTime(value, row, index){
            var pushTime = '';
            if(row.pushTime != null ){
                var date = new Date(row.pushTime);
                var Y = date.getFullYear() + '-';
                var M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
                var D = date.getDate() + ' ';
                var h = date.getHours() + ':';
                var m = date.getMinutes() + ':';
                var s = date.getSeconds();
                pushTime = Y+M+D+h+m+s;
            }
            return pushTime;
        }

        function formatGetTime(value, row, index){
            var getTime = '';
            if(row.getDate != null && row.getTime!=null){
                getTime = row.getDate + ' ' + row.getTime;
            }
            return getTime;
        }

        function formatStatus(value, row, index){
            if(row.status == '0'){
                return '未推送';
            }else if(row.status == '1'){
                return '已推送';
            }else if(row.status == '2'){
                return '推送失败';
            }else if(row.status == '3'){
                return '已出报告';
            }else if(row.status == '4'){
                return '送检单失效';
            }
        }




        function operateFormatter(value, row, index) {

            if(row.status == '0'  ){
                return '<a href="javascript:openDiv(' + ('\'' + row.sampleBaseId + '\'') + ');">样品编号</a>' +
                    '　<a href="javascript:toPush(' + ('\'' + row.sampleBaseId + '\'') + ','+
                                                        ('\'' + row.sampleNum + '\'')  + ','+
                                                        ('\'' + row.scannerTime + '\'') + ','+
                                                        ('\'' + row.tubeType + '\'') + ','+
                                                        ('\'' + row.sampleType + '\'') +');">推送</a>'
            }else if(row.status == '1'){
                return '<a href="javascript:toGet(' + ('\'' + row.sampleBaseId + '\'') + ');">获取结果</a>'
            }else if(row.status == '2'){
                return '<a href="javascript:toPush(' + ('\'' + row.sampleBaseId + '\'') + ');">推送</a>'
            }else if(row.status == '3'){
                return '<a href="javascript:toResult(' + ('\'' + row.sampleReport + '\'') + ');">查看报告</a>'
            }
        }
        //弹窗绑定样品编号
        var sampleBaseIdNum = '';
        var productCode ;
        function openDiv(sampleBaseId ) {
            sampleBaseIdNum = sampleBaseId;
            $.ajax({
                url: '/csfy/ws/getSampleBase.do?sampleBaseId='+sampleBaseId,
                type:"POST",
                dataType: 'json',
                success: function (res) {
                    success = res.code == 200;
                    if (success) {
                        if(res.rows.sampleNum !=null ){
                            $("#sampleNum").val(res.rows.sampleNum);
                        }
                        if(res.rows.sampleType !=null ){
                            $("#sampleType").selectpicker('val',(res.rows.sampleType));
                        }
                        if(res.rows.tubeType !=null ){
                            $("#tubeType").val(res.rows.tubeType);
                        }
                        productCode = res.rows.productCode;
                        $(".zhezhao").css("display","block");
                        $(".sample-alert").css("display","block");
                    } else {
                        alert(res.msg);
                    }
                }, error: function () {
                    alert('操作失败');
                }
            });

        }
        //提交样品编号
        function addSampleBaseNum() {
            var sampleNum = $("#sampleNum").val().trim();
            var sampleType = $("#sampleType").val();
            var tubeType = $("#tubeType").val();
            if(sampleNum.length == 0){
                alert("请输入样品编号");
                return false;
            }
            if(sampleType.length == 0){
                alert("请输入样品类型");
                return false;
            }
            if(productCode != 'DX0459' && tubeType.length == 0){
                alert("请输入采样管类型");
                return false;
            }

            $.ajax({
                url: '/csfy/ws/updateSampleNum.do ',
                type:"POST",
                data: { sampleBaseId: sampleBaseIdNum,sampleNum: sampleNum, sampleType: sampleType,tubeType:tubeType },
                dataType: 'json',
                success: function (res) {
                    success = res.code == 200;
                    if (success) {
                        alert('操作成功');
                        $("#sampleNum").val("");
                        $("#sampleType").selectpicker('val',(""));
                        $("#tubeType").val("");
                        $(".zhezhao").css("display","none");
                        $(".sample-alert").css("display","none");
                        searchBtnClick();
                    } else {
                        alert(res.msg);
                    }
                }, error: function () {
                    alert('操作失败');
                }
            });
//            var isAgree = confirm('确认样品编号无误？');
//            if(isAgree){
//                //调用接口绑定
//
//                //提交成功关闭弹窗
//                $(".zhezhao").css("display","none");
//                $(".sample-alert").css("display","none");
//            }
        }
        //取消关闭样品编号窗口
        function closeAlert() {
            $("#sampleNum").val("");
            $("#tubeType").val("");
            $("#sampleType").selectpicker('val',(""));
            $(".zhezhao").css("display","none");
            $(".sample-alert").css("display","none");
        }

        var date =  new Date(Date.parse(("2018-05-23").replace(/-/g,"/")));

        function toPush(sampleBaseId,sampleNum,scannerTime,tubeType,sampleType){
            var scannerTime = scannerTime.replace(/-/g,"/");
            if(sampleNum == 'null' &&  new Date(Date.parse(scannerTime)) >= date && tubeType == 'null' && sampleType == 'null'){
                alert('请输入送检单号为 ' + sampleBaseId + ' 的样本编号');
                return ;
            }

            var sampleIdList = [];
            sampleIdList.push(sampleBaseId);
            var sampleBaseIds = JSON.stringify(sampleIdList);
            var isAgree = confirm('请确认送检单'+sampleBaseId+'的样品编号为' + sampleNum + '无误？');
            if(isAgree) {
                $.ajax({
                    url: '/csfy/intf.do',
                    data: { method: "sendHuaDaSampleNew",sampleBaseIds: sampleBaseIds  },
                    success: function (res) {
                        success = res.code == 200;
                        if (success) {
                            alert('操作成功');
                            window.location.reload();
                        } else {
                            alert(res.msg);
                        }
                    }, error: function () {
                        alert('操作失败');
                    }
                });
            }
        }

        function toGet(sampleBaseId) {
            var sampleIdList = [];
            sampleIdList.push(sampleBaseId);
            var sampleBaseIds = JSON.stringify(sampleIdList);
            $.ajax({
                url: '/csfy/intf.do?method=getHuaDaSampleResultNew&sampleBaseIds='+sampleBaseIds,
                method: 'POST',
                success: function (res) {
                        success = res.code == 200;
                        if (success) {
                            alert('操作成功');
                            window.location.reload();
                        } else {
                            alert(res.msg);
                        }
                }, error: function () {
                    alert('操作失败');
                }
            });
        }


        
        function toResult(sampleReport){
            window.open(sampleReport);
        }

        //请求服务数据时所传参数
        function queryParams(params) {
            var param = {};
            var sampleName = $("#sampleName").val();
            if (sampleName != '') {
                param.sampleName = sampleName;
            }
            var sampleId = $("#sampleId").val();

            if (sampleId != null && sampleId != '') {
                param.sampleId = sampleId;
            }
            var status = $("#status").val();
            if (status != null && status != '') {
                param.status = status;
            }
            var sendHospitalName = $("#search-customer option:selected").text();
            if (sendHospitalName != '' && sendHospitalName != '请选择医院') {
                param.sendHospitalName = sendHospitalName;
            }
            var productName = $("#productName").val();
            if (productName != null && productName != '' && productName != '请选择') {
                param.productName = productName;
            }
            var couponCode = $("#couponCode").val();
            if (couponCode != null && couponCode != '') {
                param.couponCode = couponCode;
            }
            var idCard = $("#idCard").val();
            if (idCard != null && idCard != '') {
                param.cardId = idCard;
            }
            var searchStartTime = $("#search-scan-start-time").val();
            if (searchStartTime != null && searchStartTime != '') {
                param.searchStartTime = searchStartTime + " 00:00:00";
            }
            var searchEndTime = $("#search-scan-end-time").val();
            if (searchEndTime != null && searchEndTime != '') {
                param.searchEndTime = searchEndTime + " 23:59:59";
            }
            var searchResult = $("#result option:selected").text();
            if(searchResult != "" && searchResult != "请选择状态"){
                param.sampleResult = searchResult;
            }
            $("#pageSize").val( params.limit);
            $("#pageNum").val((params.offset + params.limit) / params.limit);
            param.rows = params.limit;
            param.page = (params.offset + params.limit) / params.limit;

            return param;

        }
        var deleInputSampleNum = false;
        function inputSampleNumDele(){
            if (deleInputSampleNum) {
                $("#inputSampleNum").val("");
                deleInputSampleNum = false;
            }
        }

        function whetherSearchBtnClick() {
            if(event.keyCode == "13") {
                searchBtnClick();
                deleInputSampleNum = true;
            }
        }
        //查询按钮事件
        function searchBtnClick(){
        // $('#search-btn').click(function () {
            var sampleName = $("#sampleName").val() || '';
            var sampleBaseId = $("#sampleId").val() || '';
            var status = $("#status").val() || '';
            var sendHospitalName = $("#search-customer option:selected").text() || '';
            if(sendHospitalName == "请选择医院"){
                sendHospitalName = "";
            }
            var productName = $("#productName").val() || '';
            if(productName == "请选择"){
                productName = "";
            }
            var couponCode = $("#couponCode").val() || '';

            var query = {};

            var inputSampleNum = $("#inputSampleNum").val() || '';
            if (inputSampleNum != '') {
                query.sampleNum = inputSampleNum;
            }
            if (sampleName != '') {
                query.sampleName = sampleName;
            }

            if (sampleBaseId != '') {
                query.sampleBaseId = sampleBaseId;
            }

            if (status != '') {
                query.status = status;
            }
            if (sendHospitalName != '') {
                query.sendHospitalName = sendHospitalName;
            }
            if (productName != '') {
                query.productName = productName;
            }
            //
            if (couponCode != '') {
                query.couponCode = couponCode;
            }
            var idCard = $("#idCard").val();
            if (idCard != null && idCard != '') {
                query.cardId = idCard;
            }
            var searchStartTime = $("#search-scan-start-time").val();
            if (searchStartTime != null && searchStartTime != '') {
                query.searchStartTime = searchStartTime + " 00:00:00";
            }
            var searchEndTime = $("#search-scan-end-time").val();
            if (searchEndTime != null && searchEndTime != '') {
                query.searchEndTime = searchEndTime + " 23:59:59";
            }
            var searchResult = $("#result option:selected").text();
            if(searchResult != "" && searchResult != "请选择状态"){
                query.sampleResult = searchResult;
            }

            $('#mytab').bootstrapTable('refresh', { url: '/csfy/ws/getSampleBaseList.do', query });
        };
        //tableHeight函数
        function tableHeight() {
            //可以根据自己页面情况进行调整

            return $(window).height() ;
        }

        $("#btn_get").click(function(){
            var sampleIdList = [];
            $.each( $('input:checkbox:checked'),function(){
                 if($(this).parent().next().next().next().next().next().next().next().next().next().next().next().text() =='已推送'){
                     sampleIdList.push($(this).parent().next().text());
                }
            });
            var sampleBaseIds = JSON.stringify(sampleIdList);
            if(sampleBaseIds.length>2){
                $.ajax({
                url: '/csfy/intf.do?method=getHuaDaSampleResultNew&sampleBaseIds='+sampleBaseIds,
                success: function (res) {
                    success = res.code == 200;
                    if (success) {
                        alert('操作成功');
                    } else {
                        alert(res.msg);
                    }
                    }, error: function () {
                        alert('操作失败');
                    }
                 });
            }else{
                alert("请选择已推送的送检单");
            }



        });

        //推送按钮
        $("#btn_send").click(function () {
            var sampleIdList = [];
            var failIdList = '';
            $.each( $('input:checkbox:checked'),function(){
                if( $(this).parent().next().next().next().next().next().next().next().next().next().next().next().text() =='未推送' &&
                    (($(this).parent().next().next().next().next().next().next().next().text() != '-'
//                    && new Date(Date.parse($(this).parent().next().next().next().next().next().text().replace(/-/g,"/"))) >= date) ||
//                    new Date(Date.parse($(this).parent().next().next().next().next().next().text().replace(/-/g,"/"))) < date
                    ))){
                        sampleIdList.push($(this).parent().next().text());
                }else{
                    failIdList = failIdList + "," + $(this).parent().next().text();
                }
            });
            failIdList = failIdList.substring(1,failIdList.length);
            if(failIdList.length >0 ){
                alert("请输入"+ failIdList +"的样本编号");
                return ;
            }
            var sampleBaseIds = JSON.stringify(sampleIdList);
            if(sampleBaseIds.length>2) {
                $.ajax({
                    url: '/csfy/intf.do?method=sendHuaDaSampleNew&sampleBaseIds=' + sampleBaseIds,
                    success: function (res) {
                        success = res.code == 200;
                        if (success) {
                            alert('操作成功');
                        } else {
                            alert(res.msg);
                        }
                    }, error: function () {
                        alert('操作失败');
                    }
                });
            }else{
                alert("请选择未推送的送检单");
            }
        });

        //批量审批，身份证列表
        var idList = [];
        function agreeList() {
            var rows = $("#mytab").bootstrapTable('getSelections');
            if (!rows || rows.length === 0) {
                alert('未选中操作的行');
            } else {
                var agreeList = '';
                idList.length = 0;
                rows.map(item => {
                    idList.push(item.id);
                    if (item.couponInfos && item.couponInfos.length && item.couponInfos.length > 0) {
                        var couponList = [];
                        item.couponInfos.forEach(couponItem => couponList.push(couponItem.couponName));
                        agreeList += '<p class="agree-item">' + (item.name + '，' + item.id + '，' + item.address + '，免费券：' + couponList.join("、")) + '</p>';
                    } else {
                        agreeList += '<p class="agree-item">' + (item.name + '，' + item.id + '，' + item.address + '，免费券：无') + '</p>';
                    }
                });
                $(".agree-list").html(agreeList);
                $('#agreeModel').modal('show');
            }
        }
        var angle = 0;
        $("#ic-rotate").bind("click", function (event) {
            event.stopPropagation();
            $("#id-card-photo").rotate({
                angle: angle,
                animateTo: angle + 90,
                duration: 300,
                callback: function () { angle += 90 }
            });
        });

        //上一张
        $("#id-card-photo-wrapper .arrow.l").bind("click", function (event) {
            event.stopPropagation();
            var ele = $("#id-card-photo");
            ele = ele ? ele[0] : undefined;
            if (ele) {
                var photoUrls = ele.photoUrls || [];
                var index = ele.photoIndex;
                if (index > 0) {
                    ele.photoIndex = index - 1;
                    $("#id-card-photo").attr('src', photoUrls[index - 1]);
                }
            }
        });
        //下一张
        $("#id-card-photo-wrapper .arrow.r").bind("click", function (event) {
            event.stopPropagation();
            var ele = $("#id-card-photo");
            ele = ele ? ele[0] : undefined;
            if (ele) {
                var photoUrls = ele.photoUrls || [];
                var index = ele.photoIndex;
                if (photoUrls.length > 0 && index + 1 < photoUrls.length) {
                    ele.photoIndex = index + 1;
                    $("#id-card-photo").attr('src', photoUrls[index + 1]);
                }
            }
        });


        function callParent(title,url){

            window.parent.addTab(title,url);

        }

    </script>
    <!-- 要导出的送检单table模板 -->
    <script id="table" type="text/html">
		<table border="1" class="tables">
			<tr>
				{{each ths item i}}
					<th>{{item.fieldValue}}</th>
				{{/each}} 
			</tr>
			{{each trs item i}}
			<tr>
				{{each item value i}}
					<td>{{value}}</td>
				{{/each}} 
			</tr>
			{{/each}} 
		</table> 
    </script>
</body>

</html>